<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
const parent = {
  get value() {
    return '19Qingfeng';
  },
};

const proxy = new Proxy(parent, {
  // get陷阱中target表示原对象 key表示访问的属性名
  get(target, key, receiver) {
    console.log(receiver === proxy);
    return target[key];
  },
});

const obj = {
  name: 'wang.haoyu',
};

// 设置obj继承与parent的代理对象proxy
Object.setPrototypeOf(obj, proxy);

// log: false
console.log(object);

      function loadImageAsync(url) {
        return new Promise(function (resolve, reject) {
          const image = new Image();

          image.onload = function () {
            resolve(image);
          };

          image.onerror = function () {
            console.log('2');
            image.src='https://img.php.cn/upload/article/202107/22/2021072211402814563.jpg'
            reject(image);
          };

          image.src = url;
        });
      }
      loadImageAsync(
        "https://img.php.cn/upload/article/20210ss7/22/2021072211402814563.jpg"
      ).then((res) => {
       document.body.append(res)
      }).catch(er=>{
        document.body.append(er)
      })
      // Object.defineProperty
      let datas = {
        name: 2,
        age: 3,
      };
      Object.defineProperty(datas, "name", {
        set: function (val) {
          this.age = val;
        },
        get: function () {
          return this.age;
        },
      });
      datas.name = 99;
      // console.log(datas.name);

      // proxy
      let proxy_data = {
        name: "xdj",
        age: "2",
      };
      let _proxy = new Proxy(proxy_data, {
        set: function (target, props, value, recevice) {
          target[props] = value;
        },
      });
      // console.log(_proxy);
    </script>
  </body>
</html>
